import { useReducer } from "react";
function reducer(state, action) {
    switch (action.type) {
        case "increment":
            return {
                count: state.count + 1
            }
            break;
        case "decrement":
            return {
                count: state.count - 1
            }
            break;
    }
}

export default function UseReducerDemo(){
    var [state,dispatch] = useReducer(reducer,{
        count: 0
    });
    return (
        <>
        点击次数: {state.count}<br/>
        <button onClick={()=>dispatch({type: "increment"})}>increase</button>
        <button onClick={()=>dispatch({type: "decrement"})}>decrease</button>
        </>
    );
}